package com.lanren.familybookapp.ui.me.presenter;

import com.lanren.common.base.impl.BasePresenter;
import com.lanren.familybookapp.ui.me.bean.BookInfoBean;
import com.lanren.familybookapp.ui.me.interfaces.IBookEditModel;
import com.lanren.familybookapp.ui.me.model.BookEditModel;

import java.util.List;

/**
 * @ClassName BookEditPresenter
 * @Description TODO
 * @Author chongheng.wang
 * @Date 2020/2/12 20:21
 * @Version 1.0
 */
public class BookEditPresenter extends BasePresenter<IBookEditModel.IBookEditView> {
    private BookEditModel bookEditModel;

    public BookEditPresenter(BookEditModel bookEditModel) {
        this.bookEditModel = bookEditModel;
    }

    public void updateBook(int bookId, String bookName, String bookBudget, String userInvite) {
        bookEditModel.updateBook(bookId, bookName, bookBudget, userInvite, new IBookEditModel.BookEditModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(String msg) {
                mRootView.onSuccess(msg);
            }
        });

    }

    public void getBookList(int bookId) {
        bookEditModel.getBookInfo(bookId, new IBookEditModel.GetBookEditModel() {
            @Override
            public void onError(int code, String msg) {
                mRootView.showError(code, msg);
            }

            @Override
            public void onSuccess(List<BookInfoBean> bookInfoBeans) {
                mRootView.GetBookEditSuccess(bookInfoBeans);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (bookEditModel != null) {
            bookEditModel.clearDisposable();
            bookEditModel = null;
        }
    }
}
